/*******************************************************************************
 * Copyright (c) 2007 University of Oslo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University of Oslo - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.diagram.sequence.sedi.figures;

import org.eclipse.draw2d.geometry.Rectangle;

/**
 * Subclass for figures that cover a single other object.
 * 
 * @author frankd@ifi.uio.no
 */
public abstract class InteractionFragmentFigure1
	extends SeDiSubpartFigure {
	// implements InteractionFragmentFigure {
	
	// TODO Put this method is an interface somewhere (formerly InteractionFragmentFigure)
	public Rectangle getPreferredModelBounds(final Rectangle bounds, final Rectangle coveredBounds) {
		if (coveredBounds != null) {
			int prefx = coveredBounds.x + coveredBounds.width / 2;
			int prefy;
			if (bounds.y < coveredBounds.y + LifelineFigure.HEAD_HEIGHT)
				prefy = coveredBounds.y + LifelineFigure.HEAD_HEIGHT;
			else if (bounds.bottom() > coveredBounds.bottom())
				prefy = coveredBounds.bottom() - bounds.height;
			else
				prefy = bounds.y;
			return new Rectangle(prefx, prefy, 1, 1);
		}
		else
			return bounds.getCopy();		
	}
	
	public Rectangle getPreferredFigureBounds(final Rectangle bounds, final Rectangle coveredBounds) {
		return getPreferredModelBounds(bounds, coveredBounds);
	}
	
	// --- Anchor contribution ---
	
	/*
	protected final InteractionFragmentFigureSupport 
		ifSupport =	new InteractionFragmentFigureSupport(this);
	
	public void attachTo(final LifelineFigure lifeline) {
		ifSupport.attachTo(lifeline);
	}
	
	public void detachFrom(final LifelineFigure lifeline) {
		ifSupport.detachFrom(lifeline);
	}	*/
}
